package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mqx
 * @date 2020-8-8 15:33:31
 */
@Controller
public class CartController {

    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    // 一个是添加购物车成功页面
    // window.location.href = 'http://cart.gmall.com/addCart.html?skuId=' + this.skuId + '&skuNum=' + this.skuNum
    @RequestMapping("addCart.html")
    public String addCart(@RequestParam(name = "skuId") Long skuId,
                          @RequestParam(name = "skuNum") Integer skuNum,
                          HttpServletRequest request){

            // request.getParameter("")
        // 并没有传入用户Id？
        cartFeignClient.addToCart(skuId, skuNum);

        // 页面需要skuNum, skuInfo
        request.setAttribute("skuInfo",productFeignClient.getSkuInfo(skuId));
        request.setAttribute("skuNum",skuNum);
        return "cart/addCart";
    }
    // 一个是购物车列表展示页面
    @RequestMapping("cart.html")
    public String cartList(){

        return "cart/index";
    }

}
